var url = '', jsonData = '';
$(function(){
	
	loadData();
});

function loadData() {
	/**
	 * 饼图
	 */
	loadDegree();
	loadSex();
	loadAge();
	loadWorkExperience();
	/**
	 * 部门分析
	 */
	loadDepartment();
	/**
	 * 学校分析
	 */
	loadSchool();
	/**
	 * 薪资分析
	 */
	loadSalary();
	
}

function commonAjax(){
	var result = '';
	$.ajax({
		type: 'GET',
		data: jsonData,
	    url: url,
	    async: false,
	    dataType:"json",
	    success: function(data){
	    	result = data;
	    },
	    error: function(){
	    }
	});
	return result;
}



function loadDegree(){
	
	url = ctx + '/show/shortDimissionByDegree';
	var departmentId = $('#departmentId').val();
	jsonData = {departmentId:departmentId};
	var  returnData= commonAjax();
	initPieChart(returnData.title,returnData.degree,document.getElementById('degreeMain'));
	
}

function loadAge(){
	url = ctx + '/show/shortDimissionByAge';
	var departmentId = $('#departmentId').val();
	jsonData = {departmentId:departmentId};
	var  returnData= commonAjax();
	initPieChart(returnData.title,returnData.age,document.getElementById('ageMain'));
}

function loadSex(){
	url = ctx + '/show/shortDimissionByGender';
	var departmentId = $('#departmentId').val();
	jsonData = {departmentId:departmentId};
	var  returnData= commonAjax();
	initPieChart(returnData.title,returnData.gender,document.getElementById('sexMain'));
}

function loadWorkExperience(){
	url = ctx + '/show/shortDimissionByWE';
	var departmentId = $('#departmentId').val();
	jsonData = {departmentId:departmentId};
	var  returnData= commonAjax();
	initPieChart(returnData.title,returnData.workExperience,document.getElementById('workExperienceMain'));
}

function loadDepartment(){
	
	url = ctx + '/show/shortDimissionByDept';
	var departmentId = $('#departmentId').val();
	jsonData = {departmentId:departmentId};
	var  returnData= commonAjax();
	initPeopleBarChart(returnData.title,returnData.data,returnData.dates,returnData.name1,document.getElementById('departmentMain'));
}

function loadSchool(){
	
	url = ctx + '/WastageInfoController/WastageSchoolInfo';
	var departmentId = $('#departmentId').val();
	jsonData = {departmentId:departmentId};
	var  returnData= commonAjax();
	initPeopleBarChart(returnData.title,returnData.date,returnData.dates,returnData.name1,document.getElementById('schoolMain'));
}

function loadSalary(){
	
	url = ctx + '/WastageInfoController/WastageSalaryInfo';
	var departmentId = $('#departmentId').val();
	jsonData = {departmentId:departmentId};
	var  returnData= commonAjax();
	initPieChart(returnData.title,returnData.date,document.getElementById('salaryMain'));
}
